home *** CD-ROM | disk | FTP | other *** search
-
-
-
- ffffiiiilllleeeeeeeevvvveeeennnntttt((((3333TTTTkkkk)))) ffffiiiilllleeeeeeeevvvveeeennnntttt((((3333TTTTkkkk))))
-
-
-
- NNNNAAAAMMMMEEEE
- fileevent - Execute a script when a file becomes readable or writable
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ffffiiiilllleeeeeeeevvvveeeennnntttt _f_i_l_e_I_d rrrreeeeaaaaddddaaaabbbblllleeee ?_s_c_r_i_p_t?
- ffffiiiilllleeeeeeeevvvveeeennnntttt _f_i_l_e_I_d wwwwrrrriiiittttaaaabbbblllleeee ?_s_c_r_i_p_t?
-
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- This command is used to create _f_i_l_e _e_v_e_n_t _h_a_n_d_l_e_r_s. A file event handler
- is a binding between a file and a script, such that the script is
- evaluated whenever the file becomes readable or writable. File event
- handlers are most commonly used to allow data to be received from a child
- process on an event-driven basis, so that the receiver can continue to
- interact with the user while waiting for the data to arrive. If an
- application invokes ggggeeeettttssss or rrrreeeeaaaadddd when there is no input data available,
- the process will block; until the input data arrives, it will not be
- able to service other events, so it will appear to the user to ``freeze
- up''. With ffffiiiilllleeeeeeeevvvveeeennnntttt, the process can tell when data is present and only
- invoke ggggeeeettttssss or rrrreeeeaaaadddd when they won't block.
-
- The _f_i_l_e_I_d argument to ffffiiiilllleeeeeeeevvvveeeennnntttt refers to an open file; it must be
- ssssttttddddiiiinnnn, ssssttttddddoooouuuutttt, ssssttttddddeeeerrrrrrrr, or the return value from some previous ooooppppeeeennnn
- command. If the _s_c_r_i_p_t argument is specified, then ffffiiiilllleeeeeeeevvvveeeennnntttt creates a
- new event handler: _s_c_r_i_p_t will be evaluated whenever the file becomes
- readable or writable (depending on the second argument to ffffiiiilllleeeeeeeevvvveeeennnntttt). In
- this case ffffiiiilllleeeeeeeevvvveeeennnntttt returns an empty string. The rrrreeeeaaaaddddaaaabbbblllleeee and wwwwrrrriiiittttaaaabbbblllleeee
- event handlers for a file are independent, and may be created and deleted
- separately. However, there may be at most one rrrreeeeaaaaddddaaaabbbblllleeee and one wwwwrrrriiiittttaaaabbbblllleeee
- handler for a file at a given time. If ffffiiiilllleeeeeeeevvvveeeennnntttt is called when the
- specified handler already exists, the new script replaces the old one.
-
- If the _s_c_r_i_p_t argument is not specified, ffffiiiilllleeeeeeeevvvveeeennnntttt returns the current
- script for _f_i_l_e_I_d, or an empty string if there is none. If the _s_c_r_i_p_t
- argument is specified as an empty string then the event handler is
- deleted, so that no script will be invoked. A file event handler is also
- deleted automatically whenever its file is closed or its interpreter is
- deleted.
-
- A file is considered to be readable whenever the ggggeeeettttssss and rrrreeeeaaaadddd commands
- can return without blocking. A file is also considered to be readable if
- an end-of-file or error condition is present. It is important for _s_c_r_i_p_t
- to check for these conditions and handle them appropriately; for
- example, if there is no special check for end-of-file, an infinite loop
- may occur where _s_c_r_i_p_t reads no data, returns, and is immediately invoked
- again.
-
- When using ffffiiiilllleeeeeeeevvvveeeennnntttt for event-driven I/O, it's important to read the
- file in the same units that are written from the other end. For example,
- suppose that you are using ffffiiiilllleeeeeeeevvvveeeennnntttt to read data generated by a child
- process. If the child process is writing whole lines, then you should
- use ggggeeeettttssss to read those lines. If the child generates one line at a time
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- ffffiiiilllleeeeeeeevvvveeeennnntttt((((3333TTTTkkkk)))) ffffiiiilllleeeeeeeevvvveeeennnntttt((((3333TTTTkkkk))))
-
-
-
- then you shouldn't make more than a single call to ggggeeeettttssss in _s_c_r_i_p_t: the
- first call will consume all the available data, so the second call may
- block. You can also use rrrreeeeaaaadddd to read the child's data, but only if you
- know how many bytes the child is writing at a time: if you try to read
- more bytes than the child has written, the rrrreeeeaaaadddd call will block.
-
- A file is considered to be writable if at least one byte of data can be
- written to the file without blocking, or if an error condition is
- present. Write handlers are probably not very useful without additional
- command support. The ppppuuuuttttssss command is dangerous since it write more than
- one byte at a time and may thus block. What is really needed is a new
- non-blocking form of write that saves any data that couldn't be written
- to the file.
-
- The script for a file event is executed at global level (outside the
- context of any Tcl procedure). If an error occurs while executing the
- script then the ttttkkkkeeeerrrrrrrroooorrrr mechanism is used to report the error. In
- addition, the file event handler is deleted if it ever returns an error;
- this is done in order to prevent infinite loops due to buggy handlers.
-
-
- CCCCRRRREEEEDDDDIIIITTTTSSSS
- ffffiiiilllleeeeeeeevvvveeeennnntttt is based on the aaaaddddddddiiiinnnnppppuuuutttt command created by Mark Diekhans.
-
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- tkerror
-
-
- KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
- asynchronous I/O, event handler, file, readable, script, writable
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-